﻿using System.Windows;
using System.Windows.Media;

namespace 修为尽失.辅助.exts
{
    public static class Geo
    {
        public static Point GetGeoCenter(this Geometry geo)
        {
            return geo.Bounds.Center();
        }

        public static System.Windows.Point Center(this Rect rect) => new System.Windows.Point(rect.Left + (rect.Width / 2.0), rect.Top + (rect.Height / 2.0));
        public static Rect Shift(this Rect r, double ox, double oy) => new Rect(r.X                     + ox, r.Y                      + oy, r.Width, r.Height);

        public static PathFigure ToPathFigure(this Rect rect) => new PathFigure
        {
            StartPoint = new System.Windows.Point(rect.Left, rect.Top),
            Segments = new PathSegmentCollection
            {
                ((PathSegment) new LineSegment {Point = new System.Windows.Point(rect.Right, rect.Top)}),
                ((PathSegment) new LineSegment {Point = new System.Windows.Point(rect.Right, rect.Bottom)}),
                ((PathSegment) new LineSegment {Point = new System.Windows.Point(rect.Left, rect.Bottom)})
            },
            IsClosed = true
        };
    }
}